
// 段位表
import lv from "element-ui/src/locale/lang/lv";
import el from "element-ui/src/locale/lang/el";

export const Level = [
  {"id":0,"name":"不朽车神","score":50,"star":30,"lvl":1, "total": 99999},
  {"id":1,"name":"传奇车王","score":50,"star":1,"lvl":1, "total": 5100},
  {"id":2,"name":"王者车手","score":40,"star":5,"lvl":5, "total": 3650},
  {"id":3,"name":"大师车手","score":30,"star":4,"lvl":5, "total": 1650},
  {"id":4,"name":"钻石车手","score":30,"star":3,"lvl":5, "total": 1050},
  {"id":5,"name":"铂金车手","score":50,"star":2,"lvl":3, "total": 600},
  {"id":6,"name":"黄金车手","score":50,"star":1,"lvl":3, "total": 300},
  {"id":7,"name":"白银车手","score":20,"star":2,"lvl":3, "total": 150},
  {"id":8,"name":"青铜车手","score":10,"star":1,"lvl":3, "total": 30},
]

// 获取某段的分数
export function getScore(obj) {
  let total = 0
  let tmp = 0
  const lv = Level[Number(obj.id)]
  const chklvl = lv.lvl - Number(obj.lvl) > 0 ? lv.lvl - Number(obj.lvl) : 0
  // 除了大段位的分数
  tmp = Number(obj.score) + (Number(obj.star) - 1 + chklvl * lv.star) * lv.score
  if(Number(obj.id) === 0) {
    total = Level[obj.id + 2].total
  }
  else if(Number(obj.id) < 8) {
    total = Level[obj.id + 1].total
  }
  total += tmp
  return total
}

// 获取段位对象
export function getLevel(num) {
  num = Number(num)
  let obj = {}
  let total = 0
  for (let i = 0; i < Level.length; ++i) {
    if(Level[i].total <= num) {
      if(i === 0) { obj = new Object(Level[i]) }
      else { obj = new Object(Level[i - 1]) }
      total = Level[i].total
      break
    }
  }
  if(!obj) {
    obj = new Object(Level[Level.length - 1])
    total = 0
  }
  obj.score = Math.floor((num - total) % obj.score)
  obj.lvl = 0
  const lv = obj.lvl
  obj.star = Math.floor(Math.floor((num - total) / obj.score) % lv)
  obj.lvl = Math.floor(Math.floor((num - total) / obj.score) / lv)

  return obj
}
// 1286
// 7*30+26=236  1286

